package study.saas.order.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import study.saas.common.facade.BaseFacade;
import study.saas.common.viewmodel.ApiResultV2;
import study.saas.order.entity.Commodity;

import java.math.BigDecimal;

/**
 * @author RivenChen
 */
public interface CommodityFacade extends BaseFacade<Commodity> {
    /**
     * 添加商品
     */
    ApiResultV2<Commodity> addCommodity(Integer amount, String commodityName, BigDecimal price);

    /**
     * 删除商品
     */
    ApiResultV2<Commodity> deleteCommodity(String commodityName);

    /**
     * 减少商品数量
     *
     */
    ApiResultV2<Commodity> decreaseCommodity(String commodityName);
    ApiResultV2<Commodity> increaseCommodity(String commodityName);

    /**
     * 查询商品详情
     */

    Commodity findCommodity(String commodityName);

    /**
     * 根据商品名称分页查询
      */
    Page<Commodity> findByCommodityNameContaining(String commodityName, Pageable pageable);

//    /**
//     * 设置商品状态
//     */
//    @Modifying
//    @Transactional
//    @Query("UPDATE Commodity c SET c.status = :status WHERE c.commodityName = :commodityName")
//    void updateStatusByCommodityName(@Param("commodityName") String commodityName, @Param("status") String status);
}
